package com.ruoyi.project.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.BusinessCustomerService;
import com.ruoyi.project.business.service.IBusinessCustomerServiceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 客服Controller
 * 
 * @author ruoyi
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/business/customerservice")
public class BusinessCustomerServiceController extends BaseController
{
    @Autowired
    private IBusinessCustomerServiceService businessCustomerServiceService;

    /**
     * 查询客服列表
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessCustomerService businessCustomerService)
    {
        startPage();
        List<BusinessCustomerService> list = businessCustomerServiceService.selectBusinessCustomerServiceList(businessCustomerService);
        return getDataTable(list);
    }

    /**
     * 导出客服列表
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:export')")
    @Log(title = "客服", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessCustomerService businessCustomerService)
    {
        List<BusinessCustomerService> list = businessCustomerServiceService.selectBusinessCustomerServiceList(businessCustomerService);
        ExcelUtil<BusinessCustomerService> util = new ExcelUtil<BusinessCustomerService>(BusinessCustomerService.class);
        return util.exportExcel(list, "customerservice");
    }

    /**
     * 获取客服详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessCustomerServiceService.selectBusinessCustomerServiceById(id));
    }

    /**
     * 新增客服
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:add')")
    @Log(title = "客服", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessCustomerService businessCustomerService)
    {
        return toAjax(businessCustomerServiceService.insertBusinessCustomerService(businessCustomerService));
    }

    /**
     * 修改客服
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:edit')")
    @Log(title = "客服", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessCustomerService businessCustomerService)
    {
        return toAjax(businessCustomerServiceService.updateBusinessCustomerService(businessCustomerService));
    }

    /**
     * 删除客服
     */
    @PreAuthorize("@ss.hasPermi('business:customerservice:remove')")
    @Log(title = "客服", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessCustomerServiceService.deleteBusinessCustomerServiceByIds(ids));
    }
}
